import { Inject, Controller, Get, Query } from '@midwayjs/core';
import { Context } from '@midwayjs/koa';
import { JSON } from '../decorators/json.decorator';
import { UserService } from '../service/user.service';
import { TextWechatMessage } from '../wechat/message.interface';
import { is } from '../utils/functions';
import ChatGPTService from '../service/chatgpt.service';

@Controller('/api')
export class APIController {
  @Inject()
  ctx: Context;

  @Inject()
  userService: UserService;

  @Inject()
  chatgptService: ChatGPTService;

  @Get('/get_user')
  @JSON()
  async getUser(@Query('uid') uid) {
    const user = await this.userService.getUser({ uid });
    const message: any = {
      FromUserName: '---',
      ToUserName: '',
      CreateTime: 100,
      MsgId: '',
      MsgDataId: '',
      idx: '',
      Content: '',
      MsgType: MessageType.IMAGE,
    };
    console.log('----- message is text ', [
      is<TextWechatMessage>(message),
      this.chatgptService.config,
    ]);
    return user;
  }

  @Get('/prompt')
  @JSON()
  async prompt(@Query('prompt') prompt) {
    return this.chatgptService.chat(prompt);
  }
}
